﻿using UnityEngine;

namespace MassiveBattle.Controller.Boss
{
	public class BossController_10001 : BaseBossController
	{
		#region Attack Phase1
		private void Execute_Attack_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST).GetTake(1, Query.ECount.TAUNT)))
				return;

			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST && Mathf.Abs(data.Pos - Target.Pos) <= 1).GetOrderBy(data => data == Target)))
				return;

			SetDamagePoint(SetDamagePoint_Attack_B);

			PlayTake_Attack_Source_Target();
		}
		#endregion

		#region Skill Phase1
		private void Execute_Skill_Phase1()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST)))
				return;

			SetDamagePoint(SetDamagePoint_Skill_A);

			PlayTake_Skill_Source_Target_Camera();

			AttachCamera_Skill_B();
		}
		#endregion

		#region Skill Phase2
		private Vector3 center;
		private float width = 20f;

		private void Execute_Skill_Phase2()
		{
			if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.SECOND)))
			{
				if (!SetTarget(GetCandidate().GetWhere(data => data.Line == ELine.FIRST)))
					return;
			}

			SetDamagePoint(SetDamagePoint_Skill_A);

			center = Vector3.zero;
			foreach (var targat in TargetList)
				center += targat.ModelTransform.position;
			center /= TargetList.Count;

			PlayTake_Skill_Source_Target_Start_End();
		}

		private void GenerateProjectile(GameObject resource, EventlineTake take)
		{
			var main = GameObject.Instantiate(resource) as GameObject;

			var end = new GameObject();
			end.transform.position = center + Vector3.right * (Random.Range(0, width) - width * 0.5f);

			Eventline.Play(take, new[] { main, null, ModelGameObject, end }, gameObject);

			GameObject.Destroy(end, 5f);
		}

		private void event_01()
		{
			foreach (var controller in TargetList)
				controller.Damage(PointDic[controller], true, this);
		}

		private void event_gameobject_01(object[] paramList)
		{
			var take = Manager.TakePool["MassBattle/raksha/02_skill01_projectile"];

			GenerateProjectile(paramList[0] as GameObject, take);
		}
		#endregion
	}
}
